/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JumpForm.java
 *
 * Created on Apr 17, 2011, 5:37:31 PM
 */

package sjmp;

import java.util.ArrayList;

/**
 *
 * @author Robby
 */
public class JumpForm extends javax.swing.JFrame {

    /** Creates new form JumpForm */
    public JumpForm(Player p) {
        super();
        initComponents();
        ply = p;
        list = ply.getList();
        int totalTrack = list.size();
        lblTotal.setText("of " + totalTrack);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblJumpTime = new javax.swing.JLabel();
        lblJumpTrack = new javax.swing.JLabel();
        lblSeparator = new javax.swing.JLabel();
        lblSample = new javax.swing.JLabel();
        lblTotal = new javax.swing.JLabel();
        txtMinute = new javax.swing.JTextField();
        txtSecond = new javax.swing.JTextField();
        txtTrack = new javax.swing.JTextField();
        btnGo1 = new javax.swing.JButton();
        btnGo2 = new javax.swing.JButton();
        lblMenu = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Jump Menu");
        setResizable(false);

        lblJumpTime.setText("Jump To Time  : ");

        lblJumpTrack.setText("Jump To Track : ");

        lblSeparator.setText(":");

        lblSample.setText("Ex : 4:10");

        txtMinute.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtMinute.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtMinuteKeyPressed(evt);
            }
        });

        txtSecond.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSecondKeyPressed(evt);
            }
        });

        txtTrack.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTrack.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTrackKeyPressed(evt);
            }
        });

        btnGo1.setText("Go");
        btnGo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGo1ActionPerformed(evt);
            }
        });

        btnGo2.setText("Go");
        btnGo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGo2ActionPerformed(evt);
            }
        });

        lblMenu.setFont(new java.awt.Font("Tahoma", 1, 14));
        lblMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblMenu.setText("JUMP MENU");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblJumpTrack)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTrack))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblJumpTime)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSample)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtMinute, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblSeparator)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtSecond, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnGo2))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnGo1)))
                .addGap(41, 41, 41))
            .addComponent(lblMenu, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMenu, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblJumpTime)
                    .addComponent(txtMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSeparator)
                    .addComponent(txtSecond, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGo2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblSample)
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(btnGo1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblJumpTrack)
                        .addComponent(txtTrack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGo2ActionPerformed
        // TODO add your handling code here:
        getTime();
    }//GEN-LAST:event_btnGo2ActionPerformed

    private void btnGo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGo1ActionPerformed
        // TODO add your handling code here:
        getTrack();
    }//GEN-LAST:event_btnGo1ActionPerformed

    private void txtTrackKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTrackKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == 10) {
            getTrack();
        }
    }//GEN-LAST:event_txtTrackKeyPressed

    private void txtMinuteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMinuteKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == 10) {
            getTime();
        }
    }//GEN-LAST:event_txtMinuteKeyPressed

    private void txtSecondKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSecondKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == 10) {
            getTime();
        }
    }//GEN-LAST:event_txtSecondKeyPressed

    /**
    * @param args the command line arguments
    */
    public void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JumpForm(ply).setVisible(true);
            }
        });
    }

    private void getTime() {
        Double min, sec, jumptime;
        min = Double.parseDouble(txtMinute.getText()) * 60;
        sec = Double.parseDouble(txtSecond.getText());
        jumptime = min + sec;
        ply.goTime(jumptime);
    }

    private void getTrack() {
        int idx;
        idx = Integer.parseInt(txtTrack.getText()) - 1;
        ply.goTrack(idx);
    }

    ArrayList list = new ArrayList();
    private Player ply;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JButton btnGo1;
    javax.swing.JButton btnGo2;
    javax.swing.JLabel lblJumpTime;
    javax.swing.JLabel lblJumpTrack;
    javax.swing.JLabel lblMenu;
    javax.swing.JLabel lblSample;
    javax.swing.JLabel lblSeparator;
    javax.swing.JLabel lblTotal;
    javax.swing.JTextField txtMinute;
    javax.swing.JTextField txtSecond;
    javax.swing.JTextField txtTrack;
    // End of variables declaration//GEN-END:variables


}
